package com.fairytask.engine.components.step
{
	import com.fairytask.engine.components.BaseComponent;
	import com.fairytask.engine.components.text.Label;
	import com.fairytask.engine.components.text.Text;
	import com.fairytask.engine.define.Filter;
	import com.fairytask.engine.managers.ResManager;
	import com.fairytask.engine.utils.draw.DrawAPI;
	import com.fairytask.engine.utils.draw.DrawStyle;
	
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.TextField;
	
	public class StepBar extends BaseComponent
	{
		//数据
		public var step	:uint	=	1;
		public var total	:uint	=	100;
		private var _barWidth	:uint	=	280;
		private var _barHeight	:uint	=	10;
		private var _type		:uint	=	0;
		private var _skinMc		:MovieClip	=	null;
		private var _current	:uint	=	0;
		//是否显示文字
		private var _showText	:Boolean	=	false;
		//文字内容
		private var _descText	:String	=	"";
		
		public static var BAR_FILL	:uint	=	0;//填充式
		public static var BAR_POINT	:uint	=	1;//标记式
		
		//显示
		private var _barBg		:Sprite;
		private var _bar		:Sprite;
		private var _text		:Label;
		private var _descLabel	:Label;
		//皮肤
		private var _barTxt	:TextField;
		
		public function StepBar(_w:uint=280,_h:uint=10,_desc:String="",_s:MovieClip=null,_f:uint=0,_isText:Boolean=false)
		{
			_barWidth	=	_w;
			_barHeight	=	_h;
			_type		=	_f;
			_skinMc		=	_s;
			_showText	=	_isText;
			_descText	=	_desc;
			//开始画
			drawUI();
		}
		
		private function drawUI():void
		{
			_text		=	new Label();
			_descLabel	=	new Label();
			//处理没有皮肤的
			if(_skinMc==null)
			{
				_barBg	=	new Sprite();
				DrawAPI.drawRect(_barBg.graphics,DrawStyle.getRectStyle(0,0,_barWidth,_barHeight),
					DrawStyle.getFillStyle(0x585858),DrawStyle.getLineStyle(1,0));
				_bar	=	new Sprite();
				DrawAPI.drawRect(_bar.graphics,DrawStyle.getRectStyle(0,0,_barWidth,_barHeight),
					DrawStyle.getFillStyle(0x610B0B),DrawStyle.getLineStyle(1,0));
				_bar.width	=	_barWidth*_current/total;
				
				addChild(_barBg);
				addChild(_bar);
				addChild(_text);
				addChild(_descLabel);
				_text.y	=	-3;
				
				_descLabel.htmlStrByBorder	=	_descText;
				_descLabel.y				=	_barHeight;
				_descLabel.x				=	(_barWidth-_descLabel.width)/2;
			}
			else
			{
				//TODO 要处理有皮肤的情况
				/*等有皮肤再处理*/
				addChild(_skinMc);
				_bar	=	_skinMc.bar as Sprite;
				_barTxt	=	_skinMc.barText;
				_barWidth	=	_bar.width;
			}
		}

		public function get current():uint
		{
			return _current;
		}

		public function set current(value:uint):void
		{
			_current				= 	value;
			_bar.width				=	_barWidth*_current/total;
			if(_skinMc)
			{
				_text.htmlStrByBorder	=	int(100*(_current/total)) + "%";
				_text.x					=	(_barWidth-_text.width)/2;
			}
			else
			{
				_barTxt.text	=	int(100*(_current/total)) + "%";
			}
		}

		public function get descText():String
		{
			return _descText;
		}

		public function set descText(value:String):void
		{
			_descText = value;
			_descLabel.htmlStrByBorder	=	_descText;
			_descLabel.y				=	_barHeight;
			_descLabel.x				=	(_barWidth-_descLabel.width)/2;
		}


	}
}